package comjavaday02;

import javax.swing.*;
import java.awt.*;
import java.util.Random;

public class Myfish extends JPanel implements  Runnable{
   private int[] x=new int[10];
   private int[] y=new int[10];

    public  Myfish(){
        for (int i = 0; i <x.length; i++) {
            x[i]=new Random().nextInt(1024);
            y[i]=new Random().nextInt(800);

        }
    }
    @Override
    public void paint(Graphics g) {
        super.paint(g);
        this.setBackground(Color.CYAN);
        for (int i=0;i<10;i++){

        g.setColor(Color.red);
        g.fillOval(x[i]+70,y[i]+6,7,8);
        g.setColor(Color.orange);
        g.fillOval(x[i]+22,y[i]-5,50,30);
        g.setColor(Color.black);
        g.fillOval(x[i]+60,y[i]+1,5,10);
        g.fillOval(x[i]+10,y[i],20,20);
        g.setColor(Color.CYAN);
        g.fillOval(x[i],y[i],20,20);

    }
}

    @Override
    public void run() {
        while (true){
            for (int i = 0; i <x.length ; i++) {
                x[i]=x[i]+5;
                if(x[i]>1024){
                    x[i]=0;
                    y[i]=new Random().nextInt(800);
                }
            }

            try {
                Thread.sleep(100);
            }catch (InterruptedException e){
                e.printStackTrace();
            }
               repaint();
        }
    }
}
